package com.bdsc.blogs.mirror.exception;

import com.bdsc.blogs.mirror.dto.JsonResponse;
import org.springframework.web.bind.annotation.ControllerAdvice;
import org.springframework.web.bind.annotation.ExceptionHandler;
import org.springframework.web.bind.annotation.ResponseBody;

/**
 * @author 马凯林
 */
@ControllerAdvice
public class GlobalExceptionHandler {

  @ExceptionHandler(value = MvcBusinessException.class)
  @ResponseBody
  public JsonResponse<Void> mvcBusinessExceptionHandler(MvcBusinessException e) {
    JsonResponse<Void> jsonResponse = new JsonResponse<>();
    jsonResponse.setSuccess(false);
    jsonResponse.setMessage(e.getMessage());
    jsonResponse.setErrorCode(e.getCode());
    return jsonResponse;
  }
}
